install.packages("Seurat")
library(dplyr)
library(Seurat)
library(ggplot2)
pbmc.data <- Read10X(data.dir="F:\\r\\dec\\pbmc3k_filtered_gene_bc_matrices\\filtered_gene_bc_matrices\\hg19\\")
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k",  min.cells = 3, min.features = 200)
pbmc[['percent.mt']] <- PercentageFeatureSet(pbmc, pattern = "^MT-|^mt-")
VlnPlot(pbmc, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
pbmc <- subset(pbmc, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5)
pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize", scale.factor = 10000)
all.genes <- rownames(pbmc)
pbmc <- ScaleData(pbmc, features = all.genes)
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
pbmc <- ScaleData(pbmc)
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
pbmc <- FindNeighbors(pbmc, dims = 1:10)
pbmc <- FindClusters(pbmc, resolution = 0.5)
pbmc <- RunUMAP(pbmc, dims = 1:10)
UMAPPlot(pbmc)
pbmc.markers <- FindAllMarkers(pbmc, only.pos = TRUE,min.pct = 0.25, logfc.threshold = 0.25)
top2 <-pbmc.markers %>% group_by(cluster) %>% slice_max(n = 2, order_by = avg_log2FC)
p10 <- DotPlot(object = pbmc, assay = 'RNA', features = top2$gene)+ theme(axis.text.x = element_text(angle = 45, hjust = 1))
print(p10)
FeaturePlot(pbmc, features = c("MS4A1",  "GNLY", "CD3E", "CD14", "FCER1A", "FCGR3A", "LYZ", "PPBP","CD8A"))